<template>
	<view class="u-wrap">
		<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
			<u-form-item label-width="160" :label-position="labelPosition" label="队站" prop="name">
				<u-input :border="border" placeholder="请输入队站" v-model="model.carName" type="text"></u-input>
			</u-form-item>
			<u-form-item label-width="160" :label-position="labelPosition" label="登记人" prop="name">
				<u-input :border="border" placeholder="请输入登记人" v-model="model.carName" type="text"></u-input>
			</u-form-item>
			<u-form-item label-width="160" :label-position="labelPosition" label="登记人" prop="name">
				<u-input
					:border="border"
					type="select"
					:select-open="equipmentShow"
					v-model="model.helpType"
					placeholder="请选择所在队站"
					@click="equipmentShow = true"
				></u-input>
			</u-form-item>
			<u-form-item label-width="150" :label-position="labelPosition" label="登记内容" prop="intro">
				<u-input type="textarea" :border="border" placeholder="请填写登记内容" v-model="model.intro" />
			</u-form-item>
			<view class="formItem">
				<view class="label">登记时间</view>
				<u-input :border="border" type="picker" v-model="model.buyTime" placeholder="请选择登记时间" @click="buyTimeShow = true"></u-input>
			</view>
			<view class="form_item">
				<view class="label"><text>现场图片</text></view>
				<view class="input"><u-upload ref="equipPic" width="160" height="160" upload-text="上传图片" :auto-upload="false"></u-upload></view>
			</view>
			<view class="u-m-t-40"><u-button type="primary" @click="submitForm">提交</u-button></view>
		</u-form>
		<u-action-sheet :list="equipmentList" v-model="equipmentShow" @click="equipmentCallback"></u-action-sheet>
		<u-picker mode="time" v-model="buyTimeShow" :params="params" @confirm="buyTimerConfirm"></u-picker>
	</view>
</template>

<script>
export default {
	data() {
		return {
			border: false,
			labelPosition: 'left',
			rules: [],
			errorType: ['message'],
			model: {
				carName: '',
				typeList: [{ type: '', number: '' }],
				equipList: [{ type: '', number: '' }],
				place: '',
				helpType: '',
				useYear: '',
				buyTime: ''
			},
			equipmentShow: false,
			equipmentInd: 0,
			equipmentList: [{text:'隐患登记'},{text:'轻微火灾登记'}],
			buyTimeShow: false,
			params: {
				year: true,
				month: true,
				day: true
			}
		};
	},
	methods: {
		submitForm(){
			uni.navigateBack({
				delta:1
			})
		},
		equipmentCallback(index) {
			const obj = this.model.typeList[this.equipmentInd];
			obj.type = this.equipmentList[index];
			his.model.typeList[this.equipmentInd] = obj;
		},
		addEquipment(type) {
			const _obj = { type: '', number: '' };
			if (type == 'car') {
				this.model.typeList.push(_obj);
			} else {
				this.model.equipList.push(_obj);
				equipList;
			}
		},
		helpCallback(index) {},
		equipmentSelect(ind) {
			this.equipmentInd = ind;
			this.equipmentShow = true;
		},
		equipSelect(ind) {
			this.equipInd = ind;
			this.equipShow = true;
		},
		buyTimerConfirm(e) {},
		deleteList(type, ind) {
			const list = this.model[type];
			if (list.length <= 1) {
				return false;
			}
			const _list = list.splice(ind, 1);
			this.model[type] = _list;
		}
	}
};
</script>

<style lang="scss" scoped>
.u-wrap {
	padding: 0 20rpx;
}
</style>
